package com.woniuxy.threadpool;

import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
 * <P> @Author: ideaAdmin
 * <P> TODO: Class
 * <P> TODO:
 * <P> Date: 2022/4/10:17:19
 * <P> Description:
 */
@Slf4j(topic = "c.ThreadShutdownTest")
public class ThreadShutdownTest {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(2);

        Future<Integer> result1 = pool.submit(() -> {
            log.debug("task1 running");
            Thread.sleep(1000);
            log.debug("task 1 finish");
            return 1;
        });

        Future<Integer> result2 = pool.submit(() -> {
            log.debug("task2 running");
            Thread.sleep(1000);
            log.debug("task 2 finish");
            return 2;
        });

        Future<Integer> result3 = pool.submit(() -> {
            log.debug("task3 running");
            Thread.sleep(2000);
            log.debug("task 3 finish");
            return 3;
        });

        log.debug("shutdown");
       // pool.shutdown();
        List<Runnable> runnables = pool.shutdownNow();
        runnables.forEach(System.out::println);
        //阻塞 等待
        pool.awaitTermination(3, TimeUnit.SECONDS);
        log.debug("other");


    }
}
